<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>发起砍价列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<style>
    .layui-table-cell{  /*最后的pic为字段的field*/
        height: 100%;
        max-width: 100%;
    }
   li{
        float: left;
        margin-left:80px;
        margin-top: 20px;
        width: 150px;
    }
</style>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">发起砍价列表</div>
                <div class="layui-card-body">


                    <div class="layui-form-item layui-form">

                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_name" id="shop_name" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">发起人</label>
                            <div class="layui-input-block">
                                <input type="text" name="nickname" id="nickname" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                          <div class="layui-inline">
                            <label class="layui-form-label">砍价状态</label>
                            <div class="layui-input-block">
                                <select name="is_have" lay-filter="aihao" id="is_have">
                                    <option value=""></option>
                                    <option value="0">正在砍价 </option>
                                    <option value="1">已砍成</option>
                                    <option value="2">未砍成</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate" lay-size="lg">


                    </table>

                    <script type="text/html" id="test-table-operate-barDemo">

                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="public">砍价信息</a>

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<!--用户信息详情-->
<div id="userDetail" style="display: none;padding:20px;">
        <table id="openProductTable" lay-filter="openProductTable"></table>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Bargain/bargain')}"
            ,height: 'full-155'
            ,cols: [[
                {field:'id',width:80,align:"center",  title: 'ID'}
                ,{field:'goods_name',align:"center",title: '商品名称'}
                ,{field:'nickname',align:"center",title: '发起人'}
                ,{field:'bargain_count',align:"center",title: '砍价次数'}
                ,{field:'bargain_money',align:"center",title: '被砍金额'}
                ,{field:'create_time',align:"center",title: '发起时间'}
                ,{field:'new_people',align:"center",title: '邀请新人数'}
                ,{field:'is_have',align:"center",title: '砍价状态',templet:function(d){
                        if (d.is_have == 0){
                            return "正在砍价";
                        }else if(d.is_have == 1){
                            return "已砍成";
                        }else if (d.is_have == 2){
                            return "未砍成";
                        }
                    }}
                ,{field:'bargain_time',align:"center",title: '砍成时间',templet:function(d){
                    if(d.bargain_time == null ||  d.bargain_time == undefined ){
                        return "暂无";
                    }else{
                        return d.bargain_time;
                    }
                }}
                ,{align:'center',width:350, title: '操作',fixed: 'right', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page: true
            ,limit: 20
        });

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });
        //监听是否上架
        form.on('switch(is_use_switch)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);

            var is_display = this.checked ? '1' : '0';

            $.ajax({
                url: "{:url('Bargain/isShow')}",
                type: 'post',
                dataType: 'json',
                data: {id:json.id,is_display:is_display},
                success: function(info){
                    if (info.code === 0) {
                        layer.close(loading);
                    }else{
                        layer.msg('修改失败',{icon:2,time:1000},function(){
                            window.location.reload();
                        });
                    }
                }
            })
        });
        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;

            if(obj.event === 'public'){
                layer.open({
                    type: 1, //此处以iframe举例
                    title: '砍价信息',
                    area: ['800px', '600px'],
                    shade: 0,
                    content: $("#userDetail"),
                    success:function(layero){
                        //属性管理 第一个table弹窗开始
                        table.render({
                            elem: '#openProductTable'
                            ,height: '500px'
                            ,url: "{:url('Bargain/bargain_list')}?id=" + data.id //数据接口
                            ,cols: [[ //表头
                                {field: 'nickname', title: '砍价昵称',align:"center",}
                                ,{field: 'bargain_money', title: '砍去价格', align:"center",}
                                ,{field: 'create_time', title: '砍价时间', align:"center",}
                            ]]
                            ,page: true
                            ,limit: 8
                        });

                    },

                });


            }
        });

        var $ = layui.$, active = {
            searchUserButton:function(){
                var shop_name  = $('#shop_name').val();
                var nickname = $('#nickname').val();
                var is_have = $('#is_have').val();
                table.reload('test-table-operate', {
                    where: {
                        shop_name: shop_name,
                        nickname:nickname,
                        is_have:is_have
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            },

        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });



</script>


</body>
</html>